package cn.catsdad.util;

import cn.catsdad.constant.ICommonWarningType;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 字符串工具
 *
 * @author xuyl
 * @version 1.0 2024/6/23
 */
@SuppressWarnings({ICommonWarningType.RAW_TYPES, ICommonWarningType.UNUSED})
public class StringUtil {

    public static final String EMPTY = "";

    public static String join(Object[] array, String delimiter) {
        return StringUtils.join(array, delimiter);
    }

    public static boolean isEmpty(String str) {
        return StrUtil.isEmpty(str);
    }

    public static boolean isEmpty(Iterable iterable) {
        return IterUtil.isEmpty(iterable);
    }

    public static boolean isEmpty(Object[] array) {
        return ArrayUtil.isEmpty(array);
    }

    public static boolean isEmpty(Map map) {
        return map == null || map.isEmpty();
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static boolean isNotEmpty(Iterable iterable) {
        return !isEmpty(iterable);
    }

    public static boolean isNotEmpty(Object[] array) {
        return !isEmpty(array);
    }

    public static boolean isNotEmpty(Map map) {
        return !isEmpty(map);
    }

    public static <K, T> T getValue(Map<K, T> map, K key, T defaultVale) {
        T result = defaultVale;
        if (StringUtil.isNotEmpty(map) && key != null && defaultVale != null) {
            T t = map.get(key);
            if (t != null) {
                result = t;
            }
        }
        return result;
    }

}
